package trianglejunitpackage;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.junit.*;

import trianglepackage.Triangle;

public class testTriangle {

	private static final String P_EQUILATERAL = "equilateral";
	private static final String P_ISOSCELES   = "isossceles";
	private static final String P_RIGHTANGLED = "right-angled";
	private static final String P_SCALENE     = "scalene";
	private static final String P_IMPOSSIBLE  = "impossible";
	
	private Triangle rightAngled1,rightAngled2,rightAngled3;
	private Triangle equilateral1,equilateral2;
	private Triangle isosceles1,isosceles2,isosceles3;
	private Triangle scalene1,scalene2; 
	private Triangle impossible1,impossible2,impossible3,impossible4;
	private Triangle impossibleEquilateral;
	private Triangle impossibleIsosceles;
	private Triangle negativeSide;
	private Triangle zeroSide;
	
	//BVA
	private Triangle almostRightAngled;
	private Triangle almostEquilateral;
	private Triangle almostIsoscele;
	private Triangle almostScalene;
	private Triangle almostImpossible;
	
		
	@Before
	public void setUp() {
		rightAngled1 = new Triangle(3,4,5);
		rightAngled2 = new Triangle(5,3,4);
		rightAngled3 = new Triangle(4,5,3);
		equilateral1 = new Triangle(1,1,1);
		equilateral2 = new Triangle(100,100,100);
		isosceles1 = new Triangle(2,2,3);
		isosceles2 = new Triangle(-1,-1,-1);
		isosceles3 = new Triangle(-1,-1,-1);
		impossible1 = new Triangle(2,0,2);
		impossible2 = new Triangle(1,1,-1);
		impossible3 = new Triangle(1,1,0);
		impossible4 = new Triangle(1,100,1);
		impossibleEquilateral = new Triangle(-1,-1,-1);
		impossibleIsosceles = new Triangle(-2,-2,3);
		scalene1 = new Triangle(3,5,6);
		scalene2 = new Triangle(3,2,4);
		
		almostRightAngled=new Triangle(30000,40000,50001);
		almostEquilateral=new Triangle(10000,10000,10001);
		almostIsoscele=new Triangle(20000,20001,30000);
		almostScalene=new Triangle(40000,50000,50000);
		almostImpossible=new Triangle(10000,10001,20000);
	}
	
	@Test
	public void TC5() {
		assertEquals(P_EQUILATERAL, equilateral1.classify());
	}

	@Test
	public void TC6() {
		assertEquals(P_ISOSCELES, isosceles1.classify());
	}

	@Test
	public void TC7() {
		assertEquals(P_RIGHTANGLED, rightAngled1.classify());
	}

	@Test
	public void TC8() {
		assertEquals(P_SCALENE, scalene1.classify());
	}

	@Test
	public void TC9() {
		assertEquals(P_IMPOSSIBLE, impossible2.classify());
	}

	@Test
	public void TC10() {
		assertEquals(P_IMPOSSIBLE, impossible3.classify());
	}

	// BVA
	@Test
	public void TC101(){
		assertFalse(P_RIGHTANGLED.equals(almostRightAngled.classify()));
	}

	@Test
	public void TC102(){
		assertFalse(P_EQUILATERAL.equals(almostEquilateral.classify()));
	}

	@Test
	public void TC103(){
		assertFalse(P_ISOSCELES.equals(almostIsoscele.classify()));
	}

	@Test
	public void TC104(){
		assertThat(P_SCALENE, is(not(almostScalene.classify())));
	}

	@Test
	public void TC105(){
		assertFalse(P_IMPOSSIBLE.equals(almostImpossible.classify()));
	}

	@Test
	public void TC11() {
		assertEquals(0.433, equilateral1.getArea(), 0.01);
	}

	@Test
	public void TC111() {
		assertEquals(1.984, isosceles1.getArea(), 0.01);
	}

	@Test
	public void TC112() {
		double s = (3 + 4 + 5) / 2;
		assertEquals(Math.sqrt(s * (s - 3) * (s - 4) * (s - 5)), rightAngled2.getArea(), 0.1);
	}

	@Test
	public void TC113() {
		//3,5,6
		assertEquals(7.483314773547883, scalene1.getArea(), 0.1);
	}

	@Test
	public void TC12() {
		assertEquals(-1.0, impossible2.getArea(), 0.0);
	}

	@Test
	public void TC13() {
		assertEquals(-1.0, impossible3.getArea(), 0.0);
	}

	@Test
	public void TC14() {
		assertEquals(-1.0, impossible4.getArea(), 0.0);
	}

	// getPeremiter()
	@Test
	public void TC15() {
		assertEquals(12, rightAngled1.getPerimeter());
	}

	@Test
	public void TC19() {
		assertEquals("3,2,4", scalene2.getSideLengths());
	}

	@Test
	public void TC16() {
		assertEquals(-1, impossible4.getPerimeter());
	}

	@Test
	public void TC17() {
		assertEquals(-1, impossible2.getPerimeter());
	}

	@Test
	public void TC18() {
		assertEquals(-1, impossible1.getPerimeter());
	}

	@Test
	public void TC20() {
		assertEquals("1,100,1", impossible4.getSideLengths());
	}

	@Test
	public void TC21() {
		assertEquals("1,1,-1", impossible2.getSideLengths());
	}

	@Test
	public void TC22() {
		assertEquals("1,1,0", impossible3.getSideLengths());
	}

	/**
	 * isEquilateral()
	 * TC23--TC27
	 */
	@Test
	public void TC23() {
		assertEquals(true, equilateral2.isEquilateral());
	}

	@Test
	public void TC24() {
		assertEquals(false, rightAngled3.isEquilateral());
	}

	@Test
	public void TC25() {
		assertEquals(false, impossible2.isEquilateral());
	}

	@Test
	public void TC26() {
		assertEquals(false, impossible1.isEquilateral());
	}

	@Test
	public void TC27() {
		assertEquals(false, impossibleEquilateral.isEquilateral());
	}

	//isImpossible()
	@Test
	public void TC28(){
		assertTrue(impossible1.isImpossible());
	}

	@Test
	public void TC29(){
		assertTrue(impossible2.isImpossible());
	}

	@Test
	public void TC30(){
		assertTrue(impossible3.isImpossible());
	}

	@Test
	public void TC31(){
		assertTrue(impossible4.isImpossible());
	}

	@Test
	public void TC32(){
		assertFalse(rightAngled1.isImpossible());
	}

	/**
	 * isIsosceles()
	 * TC33 -- TC37 
	 */
	@Test
	public void TC33() {
		assertFalse(impossible4.isIsosceles());
	}

	@Test
	public void TC331() {
		assertTrue(isosceles1.isIsosceles());
	}

	@Test
	public void TC34() {
		assertFalse(impossible2.isIsosceles());
	}

	@Test
	public void TC35() {
		assertFalse(impossible1.isIsosceles());
	}

	@Test
	public void TC36() {
		assertFalse(impossibleIsosceles.isIsosceles());
	}

	@Test
	public void TC37() {
		assertFalse(rightAngled3.isIsosceles());
	}

	
	//isRightAngled()
	@Test
	public void TC38(){
		assertEquals(false,impossible1.isRightAngled());
	}
	@Test
	public void TC39(){
		assertFalse(impossible2.isRightAngled());
	}
	@Test
	public void TC40(){
		assertFalse(impossible3.isRightAngled());
	}
	@Test
	public void TC41(){
		assertTrue(rightAngled1.isRightAngled());
	}
	
	/**
	 * isScalene()
	 * TC42 -- TC45
	 */
	@Test
	public void TC42() {
		assertTrue(scalene2.isScalene());
	}
	@Test
	public void TC43() {
		assertFalse(impossible2.isScalene());
	}
	@Test
	public void TC44() {
		assertFalse(impossible3.isScalene());
	}
	@Test
	public void TC45() {
		assertFalse(impossible4.isScalene());
	}

	//setSideLengths() - could not be tested in isolation since equals() is not implemented for Triangle
	@Test
	public void TC46(){
		assertEquals(new Triangle(3,4,5).getSideLengths(), equilateral1.setSideLengths(3, 4, 5).getSideLengths());
	}
	
	@Test
	public void TC47(){
		assertEquals(impossible4.getSideLengths(), equilateral1.setSideLengths(1, 100, 1).getSideLengths());
	}
	
}
